package com.fw.ui.view.settings.passwordpolicy;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.fw.service.passwordpolicy.bean.PasswordPolicyBean;
import com.fw.ui.bao.MessageBAO;
import com.fw.ui.bao.PasswordPolicyBAO;
import com.fw.ui.core.ViewDescription;
import com.fw.ui.util.UICommonUtils;
import com.fw.ui.util.VaadinApplicationObjectSupport;
import com.fw.ui.view.AbstractView;
import com.fw.ui.view.settings.passwordpolicy.event.EditPasswordPolicyClearButtonClickListener;
import com.fw.ui.view.settings.passwordpolicy.event.EditPasswordPolicySaveButtonClickListener;
import com.vaadin.data.validator.RegexpValidator;
import com.vaadin.server.Page;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

@org.springframework.stereotype.Component
@Scope(SCOPE_PROTOTYPE)
@ViewDescription(name = "settings-passwordpolicy", path = "/settings/passwordpolicy-edit")
public class EditPasswordPolicyView extends AbstractView {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    protected transient VaadinApplicationObjectSupport app;

    @Autowired
    private PasswordPolicyBAO passwordPolicyBAO;
    @Autowired
    private MessageBAO messageBAO;

    /**
     * BEAN
     */
    private PasswordPolicyBean passwordPolicyBean = new PasswordPolicyBean();

    /**
     * EVENT
     */
    @Autowired
    private EditPasswordPolicySaveButtonClickListener editPasswordPolicySaveButtonClickListener;
    @Autowired
    private EditPasswordPolicyClearButtonClickListener editPasswordPolicyClearButtonClickListener;

    // @Autowired
    // private EditPasswordPolicyMinPasswordLengthValueChangeListener editPasswordPolicyMinPasswordLengthValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyEnforePasswordHistoryValueChangeListener editPasswordPolicyEnforePasswordHistoryValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyMinUpperCaseValueChangeListener editPasswordPolicyMinUpperCaseValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyMinNumericValueChangeListener editPasswordPolicyMinNumericValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyMinSpecialCharacterValueChangeListener editPasswordPolicyMinSpecialCharacterValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyPasswordExpiryPeriodDayValueChangeListener editPasswordPolicyPasswordExpiryPeriodDayValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyAdminLoingExpirationDayValueChangeListener editPasswordPolicyAdminLoingExpirationDayValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyMerchantLoingExpirationDayValueChangeListener
    // editPasswordPolicyMerchantLoingExpirationDayValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyLoginAttemptAllowedValueChangeListener editPasswordPolicyLoginAttemptAllowedValueChangeListener;
    // @Autowired
    // private EditPasswordPolicyPasswordNotificationExpireDayValueChangeListener
    // editPasswordPolicyPasswordNotificationExpireDayValueChangeListener;

    /**
     * COMPONENT
     */
    private Panel editPasswordPolicyPanel = new Panel();

    private Label lblMinPasswordLength = new Label("", ContentMode.HTML);
    private Label lblEnforePasswordHistory = new Label("", ContentMode.HTML);
    private Label lblMinUpperCase = new Label("", ContentMode.HTML);
    private Label lblMinNumeric = new Label("", ContentMode.HTML);
    private Label lblMinSpecialCharacter = new Label("", ContentMode.HTML);
    private Label lblPasswordExpiryPeriodDay = new Label("", ContentMode.HTML);
    private Label lblAdminLoingExpirationDay = new Label("", ContentMode.HTML);
    private Label lblMerchantLoingExpirationDay = new Label("", ContentMode.HTML);
    private Label lblLoginAttemptAllowed = new Label("", ContentMode.HTML);
    private Label lblPasswordNotificationExpireDay = new Label("", ContentMode.HTML);

    private Label lblMinPasswordLengthValidateMessage = new Label("", ContentMode.HTML);
    private Label lblEnforePasswordHistoryValidateMessage = new Label("", ContentMode.HTML);
    private Label lblMinUpperCaseValidateMessage = new Label("", ContentMode.HTML);
    private Label lblMinNumericValidateMessage = new Label("", ContentMode.HTML);
    private Label lblMinSpecialCharacterValidateMessage = new Label("", ContentMode.HTML);
    private Label lblPasswordExpiryPeriodDayValidateMessage = new Label("", ContentMode.HTML);
    private Label lblAdminLoingExpirationDayValidateMessage = new Label("", ContentMode.HTML);
    private Label lblMerchantLoingExpirationDayValidateMessage = new Label("", ContentMode.HTML);
    private Label lblLoginAttemptAllowedValidateMessage = new Label("", ContentMode.HTML);
    private Label lblPasswordNotificationExpireDayValidateMessage = new Label("", ContentMode.HTML);

    private HorizontalLayout row1Validate = new HorizontalLayout();
    private HorizontalLayout row2Validate = new HorizontalLayout();
    private HorizontalLayout row3Validate = new HorizontalLayout();
    private HorizontalLayout row4Validate = new HorizontalLayout();
    private HorizontalLayout row5Validate = new HorizontalLayout();
    private HorizontalLayout row6Validate = new HorizontalLayout();
    private HorizontalLayout row7Validate = new HorizontalLayout();
    private HorizontalLayout row8Validate = new HorizontalLayout();
    private HorizontalLayout row9Validate = new HorizontalLayout();
    private HorizontalLayout row10Validate = new HorizontalLayout();

    private Button btnSave = new Button();
    private Button btnClear = new Button();

    private TextField txtMinPasswordLength = new TextField();
    private TextField txtEnforePasswordHistory = new TextField();
    private TextField txtMinUpperCase = new TextField();
    private TextField txtMinNumeric = new TextField();
    private TextField txtMinSpecialCharacter = new TextField();
    private TextField txtPasswordExpiryPeriodDay = new TextField();
    private TextField txtAdminLoingExpirationDay = new TextField();
    private TextField txtMerchantLoingExpirationDay = new TextField();
    private TextField txtLoginAttemptAllowed = new TextField();
    private TextField txtPasswordNotificationExpireDay = new TextField();

    @Override
    public void updateStrings() {

	this.lblMinPasswordLength.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.minPasswordLength"));
	this.lblEnforePasswordHistory.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.enforePasswordHistory"));
	this.lblMinUpperCase.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.minUpperCase"));
	this.lblMinNumeric.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.minNumeric"));
	this.lblMinSpecialCharacter.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.minSpecialCharacter"));
	this.lblPasswordExpiryPeriodDay.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.passwordExpiryPeriodDay"));
	this.lblAdminLoingExpirationDay.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.adminLoingExpirationDay"));
	this.lblMerchantLoingExpirationDay.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.merchantLoingExpirationDay"));
	this.lblLoginAttemptAllowed.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.loginAttemptAllowed"));
	this.lblPasswordNotificationExpireDay.setValue(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.label.passwordNotificationExpireDay"));

	this.btnSave.setCaption(this.messageBAO.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.button.save"));
	this.btnClear.setCaption(this.messageBAO.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.button.clear"));

	this.editPasswordPolicyPanel.setCaption(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.title"));
    }

    @Override
    public void init() {
	this.setSizeFull();

	this.editPasswordPolicyPanel.setSizeFull();
	this.editPasswordPolicyPanel.setId("editPasswordPolicyPanel");

	this.lblMinPasswordLengthValidateMessage
		.setId("lblMinPasswordLengthValidateMessage" + UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblEnforePasswordHistoryValidateMessage.setId("lblEnforePasswordHistoryValidateMessage"
		+ UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblMinUpperCaseValidateMessage.setId("lblMinUpperCaseValidateMessage" + UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblMinNumericValidateMessage.setId("lblMinNumericValidateMessage" + UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblMinSpecialCharacterValidateMessage.setId("lblMinSpecialCharacterValidateMessage"
		+ UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblPasswordExpiryPeriodDayValidateMessage.setId("lblPasswordExpiryPeriodDayValidateMessage"
		+ UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblAdminLoingExpirationDayValidateMessage.setId("lblAdminLoingExpirationDayValidateMessage"
		+ UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblMerchantLoingExpirationDayValidateMessage.setId("lblMerchantLoingExpirationDayValidateMessage"
		+ UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblLoginAttemptAllowedValidateMessage.setId("lblLoginAttemptAllowedValidateMessage"
		+ UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);
	this.lblPasswordNotificationExpireDayValidateMessage.setId("lblPasswordNotificationExpireDayValidateMessage"
		+ UICommonUtils.INCLUDE_VALUE_COMPONENT_PREFIX);

	this.row1Validate.setId("row1Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row2Validate.setId("row2Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row3Validate.setId("row3Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row4Validate.setId("row4Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row5Validate.setId("row5Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row6Validate.setId("row6Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row7Validate.setId("row7Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row8Validate.setId("row8Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row9Validate.setId("row9Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);
	this.row10Validate.setId("row10Validate" + UICommonUtils.INCLUDE_VISIBLE_COMPONENT_PREFIX);

	String width200px = "200px";
	String width500px = "500px";

	this.lblMinPasswordLengthValidateMessage.setWidth(width200px);
	this.lblEnforePasswordHistoryValidateMessage.setWidth(width200px);
	this.lblMinUpperCaseValidateMessage.setWidth(width200px);
	this.lblMinNumericValidateMessage.setWidth(width200px);
	this.lblMinSpecialCharacterValidateMessage.setWidth(width200px);
	this.lblPasswordExpiryPeriodDayValidateMessage.setWidth(width200px);
	this.lblAdminLoingExpirationDayValidateMessage.setWidth(width200px);
	this.lblMerchantLoingExpirationDayValidateMessage.setWidth(width200px);
	this.lblLoginAttemptAllowedValidateMessage.setWidth(width200px);
	this.lblPasswordNotificationExpireDayValidateMessage.setWidth(width200px);

	this.txtMinPasswordLength.setWidth(width200px);
	this.txtEnforePasswordHistory.setWidth(width200px);
	this.txtMinUpperCase.setWidth(width200px);
	this.txtMinNumeric.setWidth(width200px);
	this.txtMinSpecialCharacter.setWidth(width200px);
	this.txtPasswordExpiryPeriodDay.setWidth(width200px);
	this.txtAdminLoingExpirationDay.setWidth(width200px);
	this.txtMerchantLoingExpirationDay.setWidth(width200px);
	this.txtLoginAttemptAllowed.setWidth(width200px);
	this.txtPasswordNotificationExpireDay.setWidth(width200px);

	this.lblMinPasswordLengthValidateMessage.setSizeUndefined();
	this.lblEnforePasswordHistoryValidateMessage.setSizeUndefined();
	this.lblMinUpperCaseValidateMessage.setSizeUndefined();
	this.lblMinNumericValidateMessage.setSizeUndefined();
	this.lblMinSpecialCharacterValidateMessage.setSizeUndefined();
	this.lblPasswordExpiryPeriodDayValidateMessage.setSizeUndefined();
	this.lblAdminLoingExpirationDayValidateMessage.setSizeUndefined();
	this.lblMerchantLoingExpirationDayValidateMessage.setSizeUndefined();
	this.lblLoginAttemptAllowedValidateMessage.setSizeUndefined();
	this.lblPasswordNotificationExpireDayValidateMessage.setSizeUndefined();

	this.lblMinPasswordLengthValidateMessage.addStyleName("validate-error");
	this.lblEnforePasswordHistoryValidateMessage.addStyleName("validate-error");
	this.lblMinUpperCaseValidateMessage.addStyleName("validate-error");
	this.lblMinNumericValidateMessage.addStyleName("validate-error");
	this.lblMinSpecialCharacterValidateMessage.addStyleName("validate-error");
	this.lblPasswordExpiryPeriodDayValidateMessage.addStyleName("validate-error");
	this.lblAdminLoingExpirationDayValidateMessage.addStyleName("validate-error");
	this.lblMerchantLoingExpirationDayValidateMessage.addStyleName("validate-error");
	this.lblLoginAttemptAllowedValidateMessage.addStyleName("validate-error");
	this.lblPasswordNotificationExpireDayValidateMessage.addStyleName("validate-error");

	// this.txtMinPasswordLength.setMaxLength(10);

	VerticalLayout mainLayout = new VerticalLayout();
	mainLayout.setSizeFull();
	mainLayout.setSizeUndefined();
	mainLayout.setSpacing(true);
	mainLayout.setWidth("100%");

	this.editPasswordPolicyPanel.setContent(mainLayout);

	VerticalLayout formLayout = new VerticalLayout();
	formLayout.setId("formPanel");
	formLayout.setSizeUndefined();
	formLayout.setWidth("100%");
	formLayout.setSpacing(true);

	HorizontalLayout row0 = new HorizontalLayout();
	HorizontalLayout row1 = new HorizontalLayout();
	HorizontalLayout row2 = new HorizontalLayout();
	HorizontalLayout row3 = new HorizontalLayout();
	HorizontalLayout row4 = new HorizontalLayout();
	HorizontalLayout row5 = new HorizontalLayout();
	HorizontalLayout row6 = new HorizontalLayout();
	HorizontalLayout row7 = new HorizontalLayout();
	HorizontalLayout row8 = new HorizontalLayout();
	HorizontalLayout row9 = new HorizontalLayout();
	HorizontalLayout row10 = new HorizontalLayout();
	HorizontalLayout row11 = new HorizontalLayout();
	HorizontalLayout row12 = new HorizontalLayout();
	HorizontalLayout row13 = new HorizontalLayout();

	row1.setSpacing(true);
	row2.setSpacing(true);
	row3.setSpacing(true);
	row4.setSpacing(true);
	row5.setSpacing(true);
	row6.setSpacing(true);
	row7.setSpacing(true);
	row8.setSpacing(true);
	row9.setSpacing(true);
	row10.setSpacing(true);
	row12.setSpacing(true);
	row1Validate.setSpacing(true);
	row2Validate.setSpacing(true);
	row3Validate.setSpacing(true);
	row4Validate.setSpacing(true);
	row5Validate.setSpacing(true);
	row6Validate.setSpacing(true);
	row7Validate.setSpacing(true);
	row8Validate.setSpacing(true);
	row9Validate.setSpacing(true);
	row10Validate.setSpacing(true);

	row1.setSizeUndefined();
	row2.setSizeUndefined();
	row3.setSizeUndefined();
	row4.setSizeUndefined();
	row5.setSizeUndefined();
	row6.setSizeUndefined();
	row7.setSizeUndefined();
	row8.setSizeUndefined();
	row9.setSizeUndefined();
	row9.setSizeUndefined();
	row10.setSizeUndefined();
	row1Validate.setSizeUndefined();
	row2Validate.setSizeUndefined();
	row3Validate.setSizeUndefined();
	row4Validate.setSizeUndefined();
	row5Validate.setSizeUndefined();
	row6Validate.setSizeUndefined();
	row7Validate.setSizeUndefined();
	row8Validate.setSizeUndefined();
	row9Validate.setSizeUndefined();
	row10Validate.setSizeUndefined();

	row1.setWidth(width500px);
	row2.setWidth(width500px);
	row3.setWidth(width500px);
	row4.setWidth(width500px);
	row5.setWidth(width500px);
	row6.setWidth(width500px);
	row7.setWidth(width500px);
	row8.setWidth(width500px);
	row9.setWidth(width500px);
	row10.setWidth(width500px);
	row1Validate.setWidth("100%");
	row2Validate.setWidth("100%");
	row3Validate.setWidth("100%");
	row4Validate.setWidth("100%");
	row5Validate.setWidth("100%");
	row6Validate.setWidth("100%");
	row7Validate.setWidth("100%");
	row8Validate.setWidth("100%");
	row9Validate.setWidth("100%");
	row10Validate.setWidth("100%");

	this.btnSave.addStyleName("button-blue");
	this.btnClear.addStyleName("button-red");
	this.btnSave.setDisableOnClick(true);
	this.btnClear.setDisableOnClick(true);
	this.btnSave.setWidth("70px");
	this.btnClear.setWidth("70px");

	Label lblSepValidate1 = new Label("");
	Label lblSepValidate2 = new Label("");
	Label lblSepValidate3 = new Label("");
	Label lblSepValidate4 = new Label("");
	Label lblSepValidate5 = new Label("");
	Label lblSepValidate6 = new Label("");
	Label lblSepValidate7 = new Label("");
	Label lblSepValidate8 = new Label("");
	Label lblSepValidate9 = new Label("");
	Label lblSepValidate10 = new Label("");

	lblSepValidate1.setWidth(width200px);
	lblSepValidate2.setWidth(width200px);
	lblSepValidate3.setWidth(width200px);
	lblSepValidate4.setWidth(width200px);
	lblSepValidate5.setWidth(width200px);
	lblSepValidate6.setWidth(width200px);
	lblSepValidate7.setWidth(width200px);
	lblSepValidate8.setWidth(width200px);
	lblSepValidate9.setWidth(width200px);
	lblSepValidate10.setWidth(width200px);

	row1.addComponent(lblMinPasswordLength);
	row1.addComponent(txtMinPasswordLength);
	row1.setComponentAlignment(lblMinPasswordLength, Alignment.MIDDLE_RIGHT);
	row1.setComponentAlignment(txtMinPasswordLength, Alignment.MIDDLE_LEFT);

	row1Validate.addComponent(lblSepValidate1);
	row1Validate.addComponent(this.lblMinPasswordLengthValidateMessage);
	row1Validate.setComponentAlignment(this.lblMinPasswordLengthValidateMessage, Alignment.TOP_LEFT);

	row2.addComponent(lblEnforePasswordHistory);
	row2.addComponent(txtEnforePasswordHistory);
	row2.setComponentAlignment(lblEnforePasswordHistory, Alignment.MIDDLE_RIGHT);
	row2.setComponentAlignment(txtEnforePasswordHistory, Alignment.MIDDLE_LEFT);

	row2Validate.addComponent(lblSepValidate2);
	row2Validate.addComponent(this.lblEnforePasswordHistoryValidateMessage);
	row2Validate.setComponentAlignment(this.lblEnforePasswordHistoryValidateMessage, Alignment.TOP_LEFT);

	row3.addComponent(lblMinUpperCase);
	row3.addComponent(txtMinUpperCase);
	row3.setComponentAlignment(lblMinUpperCase, Alignment.MIDDLE_RIGHT);
	row3.setComponentAlignment(txtMinUpperCase, Alignment.MIDDLE_LEFT);

	row3Validate.addComponent(lblSepValidate3);
	row3Validate.addComponent(this.lblMinUpperCaseValidateMessage);
	row3Validate.setComponentAlignment(this.lblMinUpperCaseValidateMessage, Alignment.TOP_LEFT);

	row4.addComponent(lblMinNumeric);
	row4.addComponent(txtMinNumeric);
	row4.setComponentAlignment(lblMinNumeric, Alignment.MIDDLE_RIGHT);
	row4.setComponentAlignment(txtMinNumeric, Alignment.MIDDLE_LEFT);

	row4Validate.addComponent(lblSepValidate4);
	row4Validate.addComponent(this.lblMinNumericValidateMessage);
	row4Validate.setComponentAlignment(this.lblMinNumericValidateMessage, Alignment.TOP_LEFT);

	row5.addComponent(lblMinSpecialCharacter);
	row5.addComponent(txtMinSpecialCharacter);
	row5.setComponentAlignment(lblMinSpecialCharacter, Alignment.MIDDLE_RIGHT);
	row5.setComponentAlignment(txtMinSpecialCharacter, Alignment.MIDDLE_LEFT);

	row5Validate.addComponent(lblSepValidate5);
	row5Validate.addComponent(this.lblMinSpecialCharacterValidateMessage);
	row5Validate.setComponentAlignment(this.lblMinSpecialCharacterValidateMessage, Alignment.TOP_LEFT);

	row6.addComponent(lblPasswordExpiryPeriodDay);
	row6.addComponent(txtPasswordExpiryPeriodDay);
	row6.setComponentAlignment(lblPasswordExpiryPeriodDay, Alignment.MIDDLE_RIGHT);
	row6.setComponentAlignment(txtPasswordExpiryPeriodDay, Alignment.MIDDLE_LEFT);

	row6Validate.addComponent(lblSepValidate6);
	row6Validate.addComponent(this.lblPasswordExpiryPeriodDayValidateMessage);
	row6Validate.setComponentAlignment(this.lblPasswordExpiryPeriodDayValidateMessage, Alignment.TOP_LEFT);

	row7.addComponent(lblAdminLoingExpirationDay);
	row7.addComponent(txtAdminLoingExpirationDay);
	row7.setComponentAlignment(lblAdminLoingExpirationDay, Alignment.MIDDLE_RIGHT);
	row7.setComponentAlignment(txtAdminLoingExpirationDay, Alignment.MIDDLE_LEFT);

	row7Validate.addComponent(lblSepValidate7);
	row7Validate.addComponent(this.lblAdminLoingExpirationDayValidateMessage);
	row7Validate.setComponentAlignment(this.lblAdminLoingExpirationDayValidateMessage, Alignment.TOP_LEFT);

	row8.addComponent(lblMerchantLoingExpirationDay);
	row8.addComponent(txtMerchantLoingExpirationDay);
	row8.setComponentAlignment(lblMerchantLoingExpirationDay, Alignment.MIDDLE_RIGHT);
	row8.setComponentAlignment(txtMerchantLoingExpirationDay, Alignment.MIDDLE_LEFT);

	row8Validate.addComponent(lblSepValidate8);
	row8Validate.addComponent(this.lblMerchantLoingExpirationDayValidateMessage);
	row8Validate.setComponentAlignment(this.lblMerchantLoingExpirationDayValidateMessage, Alignment.TOP_LEFT);

	row9.addComponent(lblLoginAttemptAllowed);
	row9.addComponent(txtLoginAttemptAllowed);
	row9.setComponentAlignment(lblLoginAttemptAllowed, Alignment.MIDDLE_RIGHT);
	row9.setComponentAlignment(txtLoginAttemptAllowed, Alignment.MIDDLE_LEFT);

	row9Validate.addComponent(lblSepValidate9);
	row9Validate.addComponent(this.lblLoginAttemptAllowedValidateMessage);
	row9Validate.setComponentAlignment(this.lblLoginAttemptAllowedValidateMessage, Alignment.TOP_LEFT);

	row10.addComponent(lblPasswordNotificationExpireDay);
	row10.addComponent(txtPasswordNotificationExpireDay);
	row10.setComponentAlignment(lblPasswordNotificationExpireDay, Alignment.MIDDLE_RIGHT);
	row10.setComponentAlignment(txtPasswordNotificationExpireDay, Alignment.MIDDLE_LEFT);

	row10Validate.addComponent(lblSepValidate10);
	row10Validate.addComponent(this.lblPasswordNotificationExpireDayValidateMessage);
	row10Validate.setComponentAlignment(this.lblPasswordNotificationExpireDayValidateMessage, Alignment.TOP_LEFT);

	row12.addComponent(btnSave);
	row12.addComponent(btnClear);

	formLayout.addComponent(row0);
	formLayout.addComponent(row1);
	formLayout.addComponent(row1Validate);
	formLayout.addComponent(row2);
	formLayout.addComponent(row2Validate);
	formLayout.addComponent(row3);
	formLayout.addComponent(row3Validate);
	formLayout.addComponent(row4);
	formLayout.addComponent(row4Validate);
	formLayout.addComponent(row5);
	formLayout.addComponent(row5Validate);
	formLayout.addComponent(row6);
	formLayout.addComponent(row6Validate);
	formLayout.addComponent(row7);
	formLayout.addComponent(row7Validate);
	formLayout.addComponent(row8);
	formLayout.addComponent(row8Validate);
	formLayout.addComponent(row9);
	formLayout.addComponent(row9Validate);
	formLayout.addComponent(row10);
	formLayout.addComponent(row10Validate);
	formLayout.addComponent(row11);
	formLayout.addComponent(row12);
	formLayout.addComponent(row13);

	formLayout.setComponentAlignment(row1, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row2, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row3, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row4, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row5, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row6, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row7, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row8, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row9, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row10, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row12, Alignment.MIDDLE_CENTER);
	formLayout.setComponentAlignment(row1Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row2Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row3Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row4Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row5Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row6Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row7Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row8Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row9Validate, Alignment.TOP_CENTER);
	formLayout.setComponentAlignment(row10Validate, Alignment.TOP_CENTER);

	row1Validate.setVisible(false);
	row2Validate.setVisible(false);
	row3Validate.setVisible(false);
	row4Validate.setVisible(false);
	row5Validate.setVisible(false);
	row6Validate.setVisible(false);
	row7Validate.setVisible(false);
	row8Validate.setVisible(false);
	row9Validate.setVisible(false);
	row10Validate.setVisible(false);

	mainLayout.addComponent(formLayout);
	mainLayout.setComponentAlignment(formLayout, Alignment.MIDDLE_CENTER);

	this.addComponent(this.editPasswordPolicyPanel);
	this.setComponentAlignment(this.editPasswordPolicyPanel, Alignment.TOP_CENTER);
    }

    @Override
    public void initListener() {

	// this.editPasswordPolicyMinPasswordLengthValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyEnforePasswordHistoryValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyMinUpperCaseValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyMinNumericValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyMinSpecialCharacterValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyPasswordExpiryPeriodDayValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyAdminLoingExpirationDayValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyMerchantLoingExpirationDayValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyLoginAttemptAllowedValueChangeListener.setBasedComponent(this);
	// this.editPasswordPolicyPasswordNotificationExpireDayValueChangeListener.setBasedComponent(this);

	this.editPasswordPolicySaveButtonClickListener.setBasedComponent(this);
	this.editPasswordPolicyClearButtonClickListener.setBasedComponent(this);

	this.editPasswordPolicySaveButtonClickListener.setAutoEnabled(true);
	this.editPasswordPolicyClearButtonClickListener.setAutoEnabled(true);

	this.btnSave.addClickListener(this.editPasswordPolicySaveButtonClickListener);
	this.btnClear.addClickListener(this.editPasswordPolicyClearButtonClickListener);

	// this.txtMinPasswordLength.addValueChangeListener(this.editPasswordPolicyMinPasswordLengthValueChangeListener);
	// this.txtEnforePasswordHistory.addValueChangeListener(this.editPasswordPolicyEnforePasswordHistoryValueChangeListener);
	// this.txtMinUpperCase.addValueChangeListener(this.editPasswordPolicyMinUpperCaseValueChangeListener);
	// this.txtMinNumeric.addValueChangeListener(this.editPasswordPolicyMinNumericValueChangeListener);
	// this.txtMinSpecialCharacter.addValueChangeListener(this.editPasswordPolicyMinSpecialCharacterValueChangeListener);
	// this.txtPasswordExpiryPeriodDay.addValueChangeListener(this.editPasswordPolicyPasswordExpiryPeriodDayValueChangeListener);
	// this.txtAdminLoingExpirationDay.addValueChangeListener(this.editPasswordPolicyAdminLoingExpirationDayValueChangeListener);
	// this.txtMerchantLoingExpirationDay.addValueChangeListener(this.editPasswordPolicyMerchantLoingExpirationDayValueChangeListener);
	// this.txtLoginAttemptAllowed.addValueChangeListener(this.editPasswordPolicyLoginAttemptAllowedValueChangeListener);
	// this.txtPasswordNotificationExpireDay
	// .addValueChangeListener(this.editPasswordPolicyPasswordNotificationExpireDayValueChangeListener);

    }

    @Override
    public void initValidator() {

	this.txtMinPasswordLength.setImmediate(true);
	this.txtMinPasswordLength.setRequired(true);
	this.txtMinPasswordLength.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minPasswordLength.mandatory"));
	RegexpValidator minPasswordLengthRegexpValidator = new RegexpValidator("[0-9]*", true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minPasswordLength.format"));
	this.txtMinPasswordLength.addValidator(minPasswordLengthRegexpValidator);

	this.txtEnforePasswordHistory.setImmediate(true);
	this.txtEnforePasswordHistory.setRequired(true);
	this.txtEnforePasswordHistory.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.enforePasswordHistory.mandatory"));
	RegexpValidator enforePasswordHistoryRegexpValidator = new RegexpValidator("[0-9]*", true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.enforePasswordHistory.format"));
	this.txtEnforePasswordHistory.addValidator(enforePasswordHistoryRegexpValidator);

	this.txtMinUpperCase.setImmediate(true);
	this.txtMinUpperCase.setRequired(true);
	this.txtMinUpperCase.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minUpperCase.mandatory"));
	RegexpValidator minUpperCaseRegexpValidator = new RegexpValidator("[0-9]*", true,
		this.messageBAO.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minUpperCase.format"));
	this.txtMinUpperCase.addValidator(minUpperCaseRegexpValidator);

	this.txtMinNumeric.setImmediate(true);
	this.txtMinNumeric.setRequired(true);
	this.txtMinNumeric.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minNumeric.mandatory"));
	RegexpValidator minNumericLengthRegexpValidator = new RegexpValidator("[0-9]*", true,
		this.messageBAO.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minNumeric.format"));
	this.txtMinNumeric.addValidator(minNumericLengthRegexpValidator);

	this.txtMinSpecialCharacter.setImmediate(true);
	this.txtMinSpecialCharacter.setRequired(true);
	this.txtMinSpecialCharacter.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minSpecialCharacter.mandatory"));
	RegexpValidator minSpecialCharacterRegexpValidator = new RegexpValidator("[0-9]*", true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.minSpecialCharacter.format"));
	this.txtMinSpecialCharacter.addValidator(minSpecialCharacterRegexpValidator);

	this.txtPasswordExpiryPeriodDay.setImmediate(true);
	this.txtPasswordExpiryPeriodDay.setRequired(true);
	this.txtPasswordExpiryPeriodDay.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.passwordExpiryPeriodDay.mandatory"));
	RegexpValidator passwordExpiryPeriodDayRegexpValidator = new RegexpValidator("[0-9]*", true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.passwordExpiryPeriodDay.format"));
	this.txtPasswordExpiryPeriodDay.addValidator(passwordExpiryPeriodDayRegexpValidator);

	this.txtAdminLoingExpirationDay.setImmediate(true);
	this.txtAdminLoingExpirationDay.setRequired(true);
	this.txtAdminLoingExpirationDay.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.adminLoingExpirationDay.mandatory"));
	RegexpValidator adminLoingExpirationDayRegexpValidator1 = new RegexpValidator("[0-9]*", true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.adminLoingExpirationDay.format"));
	this.txtAdminLoingExpirationDay.addValidator(adminLoingExpirationDayRegexpValidator1);

	this.txtMerchantLoingExpirationDay.setImmediate(true);
	this.txtMerchantLoingExpirationDay.setRequired(true);
	this.txtMerchantLoingExpirationDay.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.merchantLoingExpirationDay.mandatory"));
	RegexpValidator merchantLoingExpirationDayRegexpValidator = new RegexpValidator(
		"[0-9]*",
		true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.merchantLoingExpirationDay.format"));
	this.txtMerchantLoingExpirationDay.addValidator(merchantLoingExpirationDayRegexpValidator);

	this.txtLoginAttemptAllowed.setImmediate(true);
	this.txtLoginAttemptAllowed.setRequired(true);
	this.txtLoginAttemptAllowed.setRequiredError(this.messageBAO
		.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.loginAttemptAllowed.mandatory"));
	RegexpValidator loginAttemptAllowedRegexpValidator = new RegexpValidator("[0-9]*", true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.loginAttemptAllowed.format"));
	this.txtLoginAttemptAllowed.addValidator(loginAttemptAllowedRegexpValidator);

	this.txtPasswordNotificationExpireDay.setImmediate(true);
	this.txtPasswordNotificationExpireDay.setRequired(true);
	this.txtPasswordNotificationExpireDay
		.setRequiredError(this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.passwordNotificationExpireDay.mandatory"));
	RegexpValidator passwordNotificationExpireDayRegexpValidator = new RegexpValidator(
		"[0-9]*",
		true,
		this.messageBAO
			.getMessage("com.fw.ui.view.settings.passwordpolicy.EditPasswordPolicyView.message.passwordNotificationExpireDay.format"));
	this.txtPasswordNotificationExpireDay.addValidator(passwordNotificationExpireDayRegexpValidator);

    }

    @Override
    public void initData() {
	try {

	    PasswordPolicyBean passwordPolicyBean = passwordPolicyBAO.getPasswordPolicy();
	    this.passwordPolicyBean = passwordPolicyBean;
	    if (passwordPolicyBean != null) {
		txtMinPasswordLength.setValue(passwordPolicyBean.getMinPasswordLength() == null ? "" : passwordPolicyBean
			.getMinPasswordLength().toString());
		txtEnforePasswordHistory.setValue(passwordPolicyBean.getEnforePasswordHistory() == null ? "" : passwordPolicyBean
			.getEnforePasswordHistory().toString());
		txtMinUpperCase.setValue(passwordPolicyBean.getMinUpperCase() == null ? "" : passwordPolicyBean.getMinUpperCase()
			.toString());
		txtMinNumeric.setValue(passwordPolicyBean.getMinNumeric() == null ? "" : passwordPolicyBean.getMinNumeric().toString());
		txtMinSpecialCharacter.setValue(passwordPolicyBean.getMinSpecialCharacter() == null ? "" : passwordPolicyBean
			.getMinSpecialCharacter().toString());
		txtPasswordExpiryPeriodDay.setValue(passwordPolicyBean.getPasswordExpiryPeriodDay() == null ? "" : passwordPolicyBean
			.getPasswordExpiryPeriodDay().toString());
		txtAdminLoingExpirationDay.setValue(passwordPolicyBean.getAdminLoingExpirationDay() == null ? "" : passwordPolicyBean
			.getAdminLoingExpirationDay().toString());
		txtMerchantLoingExpirationDay.setValue(passwordPolicyBean.getMerchantLoingExpirationDay() == null ? "" : passwordPolicyBean
			.getMerchantLoingExpirationDay().toString());
		txtLoginAttemptAllowed.setValue(passwordPolicyBean.getLoginAttemptAllowed() == null ? "" : passwordPolicyBean
			.getLoginAttemptAllowed().toString());
		txtPasswordNotificationExpireDay.setValue(passwordPolicyBean.getPasswordNotificationExpireDay() == null ? ""
			: passwordPolicyBean.getPasswordNotificationExpireDay().toString());
	    }

	} catch (Exception e) {
	    e.printStackTrace();
	    String msg = this.messageBAO.getMessage("message.error.common");
	    Notification notification = new Notification("Warning", msg, Notification.Type.WARNING_MESSAGE, true);
	    notification.setDelayMsec(1000);
	    notification.show(Page.getCurrent());
	}
    }

    public PasswordPolicyBean getPasswordPolicyBean() {
	return passwordPolicyBean;
    }

    public void setPasswordPolicyBean(PasswordPolicyBean passwordPolicyBean) {
	this.passwordPolicyBean = passwordPolicyBean;
    }

    public TextField getTxtMinPasswordLength() {
	return txtMinPasswordLength;
    }

    public TextField getTxtEnforePasswordHistory() {
	return txtEnforePasswordHistory;
    }

    public TextField getTxtMinUpperCase() {
	return txtMinUpperCase;
    }

    public TextField getTxtMinNumeric() {
	return txtMinNumeric;
    }

    public TextField getTxtMinSpecialCharacter() {
	return txtMinSpecialCharacter;
    }

    public TextField getTxtPasswordExpiryPeriodDay() {
	return txtPasswordExpiryPeriodDay;
    }

    public TextField getTxtAdminLoingExpirationDay() {
	return txtAdminLoingExpirationDay;
    }

    public TextField getTxtMerchantLoingExpirationDay() {
	return txtMerchantLoingExpirationDay;
    }

    public TextField getTxtLoginAttemptAllowed() {
	return txtLoginAttemptAllowed;
    }

    public TextField getTxtPasswordNotificationExpireDay() {
	return txtPasswordNotificationExpireDay;
    }

    public Label getLblMinPasswordLengthValidateMessage() {
	return lblMinPasswordLengthValidateMessage;
    }

    public Label getLblEnforePasswordHistoryValidateMessage() {
	return lblEnforePasswordHistoryValidateMessage;
    }

    public Label getLblMinUpperCaseValidateMessage() {
	return lblMinUpperCaseValidateMessage;
    }

    public Label getLblMinNumericValidateMessage() {
	return lblMinNumericValidateMessage;
    }

    public Label getLblMinSpecialCharacterValidateMessage() {
	return lblMinSpecialCharacterValidateMessage;
    }

    public Label getLblPasswordExpiryPeriodDayValidateMessage() {
	return lblPasswordExpiryPeriodDayValidateMessage;
    }

    public Label getLblAdminLoingExpirationDayValidateMessage() {
	return lblAdminLoingExpirationDayValidateMessage;
    }

    public Label getLblMerchantLoingExpirationDayValidateMessage() {
	return lblMerchantLoingExpirationDayValidateMessage;
    }

    public Label getLblLoginAttemptAllowedValidateMessage() {
	return lblLoginAttemptAllowedValidateMessage;
    }

    public Label getLblPasswordNotificationExpireDayValidateMessage() {
	return lblPasswordNotificationExpireDayValidateMessage;
    }

    public HorizontalLayout getRow1Validate() {
	return row1Validate;
    }

    public HorizontalLayout getRow2Validate() {
	return row2Validate;
    }

    public HorizontalLayout getRow3Validate() {
	return row3Validate;
    }

    public HorizontalLayout getRow4Validate() {
	return row4Validate;
    }

    public HorizontalLayout getRow5Validate() {
	return row5Validate;
    }

    public HorizontalLayout getRow6Validate() {
	return row6Validate;
    }

    public HorizontalLayout getRow7Validate() {
	return row7Validate;
    }

    public HorizontalLayout getRow8Validate() {
	return row8Validate;
    }

    public HorizontalLayout getRow9Validate() {
	return row9Validate;
    }

    public HorizontalLayout getRow10Validate() {
	return row10Validate;
    }

}
